import axios from 'axios'
import qs from 'qs'

const request = (type = 'GET', url = '', params = {}) => {
	const serverHost = window.host;
	let urlParams = qs.stringify(params);
	url = `${serverHost}${url}?${urlParams}`;
	return new Promise((resolve, reject) => {
		if(type == 'GET') {
			axios.get(url).then((res) => {
				resolve(res.data)
			}).catch((err) => {
				reject(err)
			})
		}
		if(type == 'POST') {
			axios.post(url, params).then((res) => {
				resolve(res.data)
			}).catch((err) => {
				reject(err)
			})
		}
	})
}

/**
 * 获取新闻分类
 */
const getNews = (param) => request('GET', '/news/type', param)

const getGameList = (param) => request('GET', '/homeGame', param)
const getTopicList = (param) => request('GET', '/topicList', param)
	/**
	 * 获取新闻列表
	 */
const getNewsList = (param) => request('GET', '/news', param)

/**
 * 获取新闻详情
 */
const getNewsDetail = (param) => request('GET', '/news/detail', param)

/**
 * 获取校历列表
 */
const getCalendarList = (param) => request('GET', '/schoolcalendar', param)

/*
  意见反馈
*/
const feedback = (param) => request('POST', '/user/Feedback', param)

/*
  课堂考勤
*/
const classRoom = (param) => request('GET', '/Attendance/ClassRoom', param)

/*
  课堂考勤详情
*/
const classRoomDetail = (param) => request('GET', '/Attendance/ClassRoomDetail', param)

/*
  早晚自习 就寝考勤
*/
const selfStudy = (param) => request('GET', '/Attendance/SelfStudy', param)

/*
  早晚自习 就寝堂考勤详情
*/
const selfStudyDetail = (param) => request('GET', '/Attendance/SelfStudyDetail', param)

/*
  教师所带班级(班主任)
*/
const teacherClass = (param) => request('GET', '/Common/TeacherClass', param)

/*
 选择学生
*/
const chooseStudent = (param) => request('GET', '/Common/SelectStudent', param)

/*
 选择班级
*/
const chooseClass = (param) => request('GET', '/Common/SelectClass', param)

/*
 作息时间表
*/
const schedule = (param) => request('GET', '/schedule', param)

/*
 获取流程列表
*/
const flowList = (param) => request('GET', '/Workflow/ApplyCenter/GetWorkFlowList', param)

/*
 获取发起流程列表
*/
const myList = (param) => request('GET', '/Workflow/ApplyCenter/GetMyApplication', param)

/*
 获取待办流程列表
*/
const waitList = (param) => request('GET', '/Workflow/ApplyCenter/GetMyWaitingTask', param)

/*
 获取已办流程列表
*/
const overList = (param) => request('GET', '/Workflow/ApplyCenter/GetMyCompleteTask', param)

/*
 获取当前流程类型
*/
const getCurrNode = (param) => request('GET', '/Workflow/ApplyCenter/GetCurrNode', param)

/*
 获取流程数据
*/
const getFlowData = (param) => request('GET', '/Workflow/GeneralApply/GetInstance', param)

/*
 获取报修类型
*/
const getRepairType = (param) => request('GET', '/Workflow/RepairApply/GetRepairType', param)

/*
获取个人素质评价报告
 */
const getQualityEvaluateReport = (param) => request('GET', '/EvaluationService/GetQualityEvaluationReport', param)
/*
根据班主任ID获取其管理的班级
 * */
const getTeacherClass = (param) => request('GET', '/EvaluationService/GetTeacherClass', param) 
/*
 根据领导/班主任ID获取其对应的专业/班级
 * */
const getTeacherSpecialty = (param) => request('GET', '/StatisticService/GetTeacherSpecialty', param) 
/*
 获取（有评测数据的）学期
 * */
const getSemester = (param) => request('GET', '/StatisticService/GetSemester', param) 

/*获取报表统计*/
const getStudentCount = (param) => request('GET', '/Internship/GetStudentCount', param)

/*是否为班主任*/
const getIsHeadTeacher = (param) => request('GET', '/Internship/IsHeadTeacher', param)

export {
	getNews,
	getNewsList,
	getNewsDetail,
	getCalendarList,
	feedback,
	getGameList,
	getTopicList,
	classRoom,
	classRoomDetail,
	selfStudy,
	selfStudyDetail,
	teacherClass,
	chooseStudent,
	chooseClass,
	schedule,
	flowList,
	myList,
	waitList,
	overList,
	getCurrNode,
	getFlowData,
	getRepairType,
	getQualityEvaluateReport,
	getTeacherClass,
	getTeacherSpecialty,
	getSemester,
	getStudentCount,
	getIsHeadTeacher
}